package com.zut.yunxi.yunxi.controller;

import java.util.Arrays;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zut.yunxi.yunxi.entity.TOrderEntity;
import com.zut.yunxi.yunxi.service.TOrderService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;



/**
 * 
 *
 * @author liqiqi
 * @email 523892377@qq.com
 * @date 2020-07-13 22:22:53
 */
@RestController
@RequestMapping("/yunxi/torder")
public class TOrderController {
    @Autowired
    private TOrderService tOrderService;

    /**
     * 列表
     */
    @Cacheable(value = "torderlist",key = "#params")
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tOrderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @Cacheable(value = "torderinfo",key = "#id")
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TOrderEntity tOrder = tOrderService.getById(id);

        return R.ok().put("tOrder", tOrder);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TOrderEntity tOrder){
		tOrderService.save(tOrder);

        return R.ok();
    }

    /**
     * 修改
     */
    @CachePut(value = "torderinfo",key = "#tOrder")
    @RequestMapping("/update")
    public R update(@RequestBody TOrderEntity tOrder){
		tOrderService.updateById(tOrder);

        return R.ok();
    }

    /**
     * 删除
     */
    @CacheEvict( value = "torderinfo",key = "#ids")
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		tOrderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
